<form class="form-horizontal" id="winModal">
    <input id="id" name="id" type="hidden">
    <div class="form-group">
        <label class="col-sm-3 control-label text-left">角色名称：</label>
        <div class="col-sm-8">
            <input id="roleName" name="roleName" class="form-control" type="text" placeholder="请输入角色名称">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label text-left">角色标示：</label>
        <div class="col-sm-8">
            <input id="roleKey" name="roleKey" class="form-control" type="text" placeholder="请输入角色标示">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label text-left">权限资源：</label>
        <div class="col-sm-8">
            <div class="form-control myTreeBox">
                <input id="ids" name="ids" type="hidden">
                <ul id="resTree" class="ztree "></ul>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label text-left">角色排序：</label>
        <div class="col-sm-8">
            <input id="sort" name="sort" class="form-control" type="number" value="0" min="0" placeholder="请输入排序编号">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label text-left">信息备注：</label>
        <div class="col-sm-8">
            <input id="description" name="description" class="form-control" type="text" placeholder="请输入备注">
        </div>
    </div>
</form>
<script type="text/javascript">
    $(function () {
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#winModal").validate({
            rules: {
                roleName: {
                    required: true,
                    rangelength: [2, 50],
                    stringAllName: true,
                    remote: {
                        url: "check.json",
                        type: "post",
                        data: {
                            roleName: function () {
                                return $("#roleName").val();
                            },
                            id: function () {
                                return $("#id").val();
                            }
                        }
                    }
                },
                roleKey: {
                    required: true,
                    rangelength: [2, 50],
                    stringEnName: true,
                    remote: {
                        url: "check.json",
                        type: "post",
                        data: {
                            roleKey: function () {
                                return $("#roleKey").val();
                            },
                            id: function () {
                                return $("#id").val();
                            }
                        }
                    }
                },
                ids: {
                    required: true
                },
                sort: {
                    required: true,
                    digits: true
                },
                description: {
                    required: false,
                    rangelength: [0, 50]
                }
            },
            messages: { //自定义验证消息
                roleName: {
                    required: e + "请输入角色名称",
                    stringAllName: e + "只能包括中文、英文、数字和下划线，数字和下划线不能开头",
                    rangelength: $.validator.format(e + "角色名称位数要在{0}-{1}个字符之间。"),
                    remote: $.validator.format(e + "角色名称“{0}”已经被占用。")
                },
                roleKey: {
                    required: e + "请输入角色标示",
                    stringEnName: e + "只能包括英文、数字和下划线，下划线不能开头",
                    rangelength: $.validator.format(e + "角色标示位数要在{0}-{1}个字符之间。"),
                    remote: $.validator.format(e + "角色标示“{0}”已经被占用。")
                },
                ids: {
                    required: e + "请选择角色资源"
                },
                description: {
                    required: e + "请输入备注信息",
                    rangelength: $.validator.format(e + "备注信息长度要在{0}-{1}个字符之间。"),
                },
                sort: {
                    required: e + "排序编号不正确，只允许为正整数"
                }
            }
        });

    });
</script>